<template>
  <div class="toggleLanguage">
    <el-select
      v-model="value"
      size="mini"
      placeholder="请选择"
      @change="languageChange"
      popper-class="mySelect"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: [
        {
          value: "zh",
          label: "简体中文",
        },
        {
          value: "en",
          label: "English",
        },
      ],
      value:
        localStorage.getItem("languageSet") == "zh" ? "简体中文" : "English",
    };
  },
  methods: {
    languageChange(data) {
      this.$i18n.locale = data;
      localStorage.setItem("languageSet", this.$i18n.locale);
      this.$emit("languageChange");
    },
  },
};
</script>

<style lang="less" scoped>
.toggleLanguage {
  position: absolute;
  right: 70px;
  top: 8px;
  width: 95px;
}
</style>